import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import fs from 'fs'
import tailwindcss from '@tailwindcss/vite'

const pathSrc = path.resolve(__dirname, 'src')
// const host = "http://172.16.50.103";

export default defineConfig({
  plugins: [
    vue(),
    tailwindcss(),
    Components({
      useSource: true,
      extensions: ['vue', 'md'],
      include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
      resolvers: [
        ElementPlusResolver({
          importStyle: 'sass'
        })
      ]
    })
  ],
  server: {
    // https: {//这里是需要用来调试https的时候放开
    //   key: fs.readFileSync('ssl.key'),
    //   cert: fs.readFileSync('ssl.cert')
    // },
    port: 8888,
    host: 'localhost',
    proxy: {
      '/api': {
        target: 'http://localhost:23108/api',
        changeOrigin: true,
        secure: false,
        // headers: {
        //   "Referer": `${host}`
        // },
        rewrite: path => path.replace(/^\/api/, '')
      },
      "/images": {
        target: "http://localhost:23108",
        changeOrigin: true,
        secure:false,
      },
    }
  },
  resolve: {
    alias: {
      '~/': `${pathSrc}/`
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `
          @use "./src/styles/variables.scss" as *;
        `
      }
    }
  }
})
